<div style="height:500px;width:900px;overflow-y:auto;overflow-x:hidden;">
    <div class="clearfix ng-scope ml25" ng-if="invoiceType!=4 && invoiceType != 3">
        <button class="btn" href="#" ng-click="showInvoiceImport()">引入未关联合同{{invoiceName||'发票'}}</button>
    </div>
    <form name="invoiceEditForm" class="form-horizontal" novalidate>
        <div class="form-group mt10 clearfix" ng-if="invoiceName!='收据'">
            <span class="col-sm-3 control-label">{{invoiceName||'发票'}}类别</span>

            <div class="col-sm-9" ng-if="invoiceName=='发票'">
                <input id="category" select2 ng-model="invoiceInfo.invoice_category" select2-model="ddl2InvoiceCategory"
                       config="ddlConfigInvoiceCategory" class="form-control" type="text" placeholder="发票类别"

                       name="invoice_category" required/>
                <span role="alert"
                      ng-show="(invoiceEditForm.$submitted || invoiceEditForm.invoice_category.$touched) && invoiceEditForm.invoice_category.$error.required"
                      class="error ng-hide c-red lh30">发票类别不能为空</span>
            </div>
            <div class="col-sm-9" ng-if="invoiceName=='收据'">
                <input select2 ng-model="invoiceInfo.invoice_category" select2-model="ddl2InvoiceCategory"
                       config="ddlConfigInvoiceCategory" class="form-control" type="text" placeholder="收据类别"
                       name="invoice_category"/>
            </div>

            <span class="col-sm-3 control-label">{{invoiceName||'发票'}}代码</span>

            <div class="col-sm-9">
                <input type="text" ng-model="invoiceInfo.invoice_code" class="form-control" id="inputPrice"
                       placeholder="{{invoiceName||'发票'}}代码"

                       name="invoice_code" {{invoiceName=='收据'?'':'required'}}>
                <span role="alert"
                      ng-show="(invoiceEditForm.$submitted || invoiceEditForm.invoice_code.$touched) && invoiceEditForm.invoice_code.$error.required"
                      class="error ng-hide c-red lh30">{{invoiceName||'发票'}}代码不能为空</span>
            </div>
        </div>
        <div class="form-group mt10 clearfix" ng-if="invoiceName!='收据'">{{invoiceInfo.invoiceType}}
            <span class="col-sm-3 control-label">{{invoiceName||'发票'}}类型</span>

            <div class="col-sm-9" ng-if="invoiceName=='发票'">
                <input id="itype" select2 ng-model="invoiceInfo.invoice_type" select2-model="ddl2InvoiceType"
                       config="ddlConfigInvoiceType" class="form-control" type="text" placeholder="发票类型"

                       name="invoice_type" required/>
                <span role="alert"
                      ng-show="(invoiceEditForm.$submitted || invoiceEditForm.invoice_type.$touched) && invoiceEditForm.invoice_type.$error.required"
                      class="error ng-hide c-red lh30">发票类型不能为空</span>
            </div>
            <div class="col-sm-9" ng-if="invoiceName=='收据'">
                <input select2 ng-model="invoiceInfo.invoice_type" select2-model="ddl2InvoiceType"
                       config="ddlConfigInvoiceType" class="form-control" type="text" placeholder="收据类型"
                       name="invoice_type"/>
            </div>

            <span class="col-sm-3 control-label">{{invoiceName||'发票'}}号码</span>

            <div class="col-sm-9">
                <input type="text" ng-model="invoiceInfo.invoice_no" class="form-control" id="inputPrice"
                       placeholder="{{invoiceName||'发票'}}号码"

                       name="invoice_no" {{invoiceName=='收据'?'':'required'}}>
                <span role="alert"
                      ng-show="(invoiceEditForm.$submitted || invoiceEditForm.invoice_no.$touched) && invoiceEditForm.invoice_no.$error.required"
                      class="error ng-hide c-red lh30">{{invoiceName||'发票'}}号码不能为空</span>
            </div>
        </div>
        <div class="form-group mt10 clearfix">
            <span class="col-sm-3 control-label">申请人</span>

            <div class="col-sm-9">
                <div>
                    <input id="idProposer" name="proposer_id" select2 required ng-model="invoiceInfo.proposer_id"
                           select2-model="ddl2InvoiceProposer"
                           ng-disabled="false"
                           config="ddlConfigInvoiceProposer" type="text" placeholder="申请人"
                           class="form-control idProposer">
                </div>

                <span role="alert"
                      ng-show="(invoiceEditForm.$submitted || invoiceEditForm.proposer_id.$touched) && invoiceEditForm.proposer_id.$error.required"
                      class="error ng-hide c-red lh30">申请人不能为空</span>
            </div>

            <span class="col-sm-3 control-label">客户名称</span>

            <div class="col-sm-9">
                <input type="text" name="customer_name" required class="form-control"

                       ng-model="invoiceInfo.customer_name" placeholder="客户名称">
                    <span role="alert"
                          ng-show="(invoiceEditForm.$submitted || invoiceEditForm.customer_name.$touched) && invoiceEditForm.customer_name.$error.required"
                          class="error ng-hide c-red lh30">客户名称不能为空</span>
            </div>

        </div>
        <div class="form-group mt10 clearfix">
            <span class="col-sm-3 control-label">开票单位</span>

            <div class="col-sm-9">
                <div>
                    <input id="idInvoiceCompany" name="invoice_company_id"
                           type="text"
                           class="form-control idInvoiceCompany"
                           disabled="disabled"
                           value="明源云链">
                </div>


                <span role="alert"
                      ng-show="(invoiceEditForm.$submitted || invoiceEditForm.invoice_company_id.$touched) && invoiceEditForm.invoice_company_id.$error.required"
                      class="error ng-hide c-red lh30">开票单位不能为空</span>
            </div>
            <span class="col-sm-3 control-label">开票金额</span>

            <div class="col-sm-9">
                <input type="number" name="invoice_amount" required class="form-control invoice-amount"
                       ng-model="invoiceInfo.invoice_amount" placeholder="开票金额">
                    <span role="alert"
                          ng-show="(invoiceEditForm.$submitted || invoiceEditForm.invoice_amount.$touched) && invoiceEditForm.invoice_amount.$error.required"
                          class="error ng-hide c-red lh30">开票金额不能为空</span>
                    <span role="alert"
                          ng-show="(invoiceEditForm.$submitted || invoiceEditForm.invoice_amount.$touched) && invoiceEditForm.invoice_amount.$error.number"
                          class="error ng-hide c-red lh30">开票金额必须为数值类型</span>
                    <span role="alert"
                          ng-show="(invoiceEditForm.$submitted || invoiceEditForm.invoice_amount.$touched) && totalEqualAmount()"
                          class="error ng-hide c-red lh30">摘要金额总和必须等于开票金额</span>
            </div>
        </div>
        <div class="form-group mt10 clearfix">

            <span class="col-sm-3 control-label">开票时间</span>

            <div class="col-sm-9">
                <input type="text" name="invoice_date" required class="form-control input-date"
                       ng-model="invoiceInfo.invoice_date" ui-date
                       format="yyyy-MM-dd"
                       style="width: 100%" placeholder="开票时间">
                    <span role="alert"
                          ng-show="(invoiceEditForm.$submitted || invoiceEditForm.invoice_date.$touched) && invoiceEditForm.invoice_date.$error.required"
                          class="error ng-hide c-red lh30">开票时间不能为空</span>
            </div>

            <span class="col-sm-3 control-label" ng-if="invoiceInfo.is_child_invoice == 1">主发票</span>

            <div class="col-sm-9" ng-if="invoiceInfo.is_child_invoice == 1">
                <input select2 ng-model="invoiceInfo.main_invoice_id" select2-model="ddl2InvoiceMainInvoice"

                       config="ddlConfigMainInvoice" class="form-control idMainInvoice" type="text" placeholder="主发票"
                       required name="main_invoice_id"/>
                <span role="alert"
                      ng-show="(invoiceEditForm.$submitted || invoiceEditForm.main_invoice_id.$touched) && invoiceEditForm.main_invoice_id.$error.required"
                      class="error ng-hide c-red lh30">主发票不能为空</span>
            </div>
        </div>
        <div class="form-group mt10 clearfix">
            <span class="col-sm-3 control-label">开票摘要</span>

            <div class="col-sm-21">
                <button type="button" class="btn btn-yellow" ng-click="newInvoiceAbstract()"
                        >新增{{invoiceName||'发票'}}摘要
                </button>
                <div class="table-wrap mh60 mt10">
                    <table class="table">
                        <thead>
                        <tr>
                            <th style="width: 40px;">序号</th>
                            <th>摘要类型</th>
                            <th style="width: 250px;" class="align-r">金额</th>
                            <th style="width: 90px;" class="align-m">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr ng-repeat="record in invoiceInfo.invoiceSummarys">
                            <td><p ng-bind="$index + 1"></p></td>
                            <td class="pt10 pb10">
                                <input name="summary_type" select2 required ng-model="record.summary_type"
                                       select2-model="ddl2InvoiceSummary"
                                       config="ddlConfigInvoiceSummaryType" type="text" placeholder="摘要类型"

                                       class="form-control">
                                    <span role="alert"
                                          ng-show="(invoiceEditForm.$submitted || invoiceEditForm.summary_type.$touched) && invoiceEditForm.summary_type.$error.required"
                                          class="error ng-hide c-red lh30">摘要类型不能为空</span>
                            </td>
                            <td>
                                <input type="text" name="summary_amount" required number
                                       class="form-control summary-amount align-r"
                                       ng-model="record.summary_amount"

                                       placeholder="摘要金额">
                            </td>
                            <td class="align-m">
                                <p ng-if="invoiceInfo.invoiceSummarys.length>1 && invoiceType != 3 && !invoiceInfo.invoice_id">
                                    <a
                                            href="javascript:;"
                                            ng-click="removeInvoiceAbstract($index)">删除</a>
                                </p>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <span role="alert"
                          ng-show="(invoiceEditForm.$submitted || invoiceEditForm.summary_amount.$touched) && vaildSummaryRequired()"
                          class="error ng-hide c-red lh30">摘要金额不能为空</span>
                    <span role="alert"
                          ng-show="(invoiceEditForm.$submitted || invoiceEditForm.summary_amount.$touched) && vaildSummaryNumber()"
                          class="error ng-hide c-red lh30">摘要金额必须为数值类型</span>
                </div>
            </div>
        </div>

        <div class="form-group mt10 clearfix">
            <span class="col-sm-3 control-label">备注</span>

            <div class="col-sm-21">
                <textarea type="text" ng-model="invoiceInfo.remark" class="form-control" id="inputPrice"
                          placeholder="备注" rows="4"></textarea>
            </div>
        </div>

    </form>

    <div class="mt20 clearfix ng-scope ml10" ng-if="invoiceType != 3">
        <span class="fl lh30 f14">应收信息</span>
    </div>
    <div id="grid" class="table-wrap mt10 ml10" style="min-height: 200px;" ng-if="invoiceType != 3">

        <table width="100%">
            <thead>
            <tr>
                <th width="30"></th>
                <th width="40">序号</th>
                <th>款项名称</th>
                <th width="170">应收信息</th>
                <th width="175">开票金额</th>
                <th width="108">已关联发票</th>
                <th width="108">备注</th>
            </tr>
            </thead>
            <tbody>
            <tr ng-repeat="record in editInvoiceReceivables">
                <td class="align-m"><input type="checkbox" ng-model="record._checked" ng-change="shareAmount()"></td>
                <td height="40"><p ng-bind="$index + 1"></p></td>
                <td class="lh14">
                    <p ng-bind="record.receivable_item_name"></p>

                    <p>款项小类:{{record.money_category_item_name}}</p>
                </td>
                <td>
                    <p>应收金额:{{record.receivable_amount | number:2}}</p>

                    <p>应收日期:{{record.receivable_date|strdate:'yyyy-MM-dd'}}</p>
                </td>
                <td>
                    <p>已开票金额:{{record.billing_amount | number:2}}</p>

                    <p>待开票金额:{{(record.receivable_amount - record.billing_amount - record.cur_billing_amount) < 0 ? 0 : (record.receivable_amount - record.billing_amount - record.cur_billing_amount) |
                    number:2}}</p>

                    <p>本次开票金额:{{record.cur_billing_amount | number:2}}</p>
                </td>
                <td>
                    <p ng-bind="record.billing_invoice_no"></p>
                </td>
                <td>
                    <p ng-bind="record.remark"></p>
                </td>

            </tr>
            </tbody>
        </table>
        <div class="no-data" ng-if="funds.length == 0" style="height:180px"><span>暂无数据</span></div>

    </div>
</div>


<div id="importInvoiceDlg" class="importInvoiceDlg"
     style="overflow-y:auto;overflow-x:hidden;display: none;height:450px;">
    <input type="text" class="fl input-text w200 ml10" placeholder="客户名称/发票号码"
           ng-model="query.keyword"
           ng-enter="query.execute()">
    <button class="btn ml10" ng-click="query.execute()">查询</button>
    <div id="grid" class="table-wrap mt10 ml10" style="min-height: 200px;">

        <table width="100%" class="valign-t">
            <thead>
            <tr>
                <th width="40">序号</th>
                <th width="180">发票信息</th>
                <th width="90" class="align-r">开票金额</th>
                <th width="120">客户名称</th>
                <th>开票单位</th>
            </tr>
            </thead>
            <tbody>
            <tr ng-repeat="record in importInvoices" ng-click="selectInvoice(record)"
                ng-class="{selected:record.__selected}">
                <td height="40"><p ng-bind="$index + 1"></p></td>
                <td class="lh14">
                    <p>发票代码:{{record.invoice_code}}</p>

                    <p>发票号码:<em class="c-red">{{record.invoice_no}}</em></p>

                    <p>发票类别:{{record.invoice_category==0?'销售票':'服务票'}}</p>

                    <p>发票类型:{{record.invoice_type==0?'增值税普通发票':'增值税专用发票'}}</p>

                </td>
                <td class="align-r">
                    <p ng-bind="record.invoice_amount|number:2"></p>
                </td>
                <td>
                    <p ng-bind="record.customer_name"></p>
                </td>
                <td>
                    <p ng-bind="record.BUName"></p>
                </td>
            </tr>
            </tbody>
        </table>
        <div class="no-data" ng-if="importPayments.length == 0" style="height:180px"><span>暂无数据</span></div>

    </div>

    <style type="text/css">
        .selected, .selected td {
            background: #fff9ee !important;
        }
    </style>
</div>